const WebSocket = require("ws");

const ws = new WebSocket("ws://localhost:8080");

ws.on("open", () => {
  console.log("已连接到服务器");

  // 发送消息到服务器
  ws.send("你好，服务器！");
});

ws.on("message", (message) => {
  console.log(`收到服务器消息: ${message}`);
});

ws.on("close", () => {
  console.log("连接已关闭");
});

ws.on("error", (error) => {
  console.error("WebSocket 错误:", error);
});
